package org.tuoren.official.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tuoren.common.core.domain.R;
import org.tuoren.common.core.validate.AddGroup;
import org.tuoren.common.core.validate.EditGroup;
import org.tuoren.common.excel.utils.ExcelUtil;
import org.tuoren.common.idempotent.annotation.RepeatSubmit;
import org.tuoren.common.log.annotation.Log;
import org.tuoren.common.log.enums.BusinessType;
import org.tuoren.common.mybatis.core.page.PageQuery;
import org.tuoren.common.mybatis.core.page.TableDataInfo;
import org.tuoren.common.web.core.BaseController;
import org.tuoren.official.domain.bo.TServiceCenterDetailBo;
import org.tuoren.official.domain.vo.TServiceCenterDetailVo;
import org.tuoren.official.service.ITServiceCenterDetailService;

import java.util.List;

/**
 * 服务中心详情
 *
 * @author Lion Li
 * @since 2024-11-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/official/serviceCenterDetail")
public class TServiceCenterDetailController extends BaseController {

    private final ITServiceCenterDetailService tServiceCenterDetailService;

    /**
     * 查询服务中心详情列表
     */
    @SaCheckPermission("official:serviceCenterDetail:list")
    @GetMapping("/list")
    public TableDataInfo<TServiceCenterDetailVo> list(TServiceCenterDetailBo bo, PageQuery pageQuery) {
        return tServiceCenterDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务中心详情列表
     */
    @SaCheckPermission("official:serviceCenterDetail:export")
    @Log(title = "服务中心详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TServiceCenterDetailBo bo, HttpServletResponse response) {
        List<TServiceCenterDetailVo> list = tServiceCenterDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务中心详情", TServiceCenterDetailVo.class, response);
    }

    /**
     * 获取服务中心详情详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("official:serviceCenterDetail:query")
    @GetMapping("/{id}")
    public R<TServiceCenterDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tServiceCenterDetailService.queryById(id));
    }

    /**
     * 新增服务中心详情
     */
    @SaCheckPermission("official:serviceCenterDetail:add")
    @Log(title = "服务中心详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TServiceCenterDetailBo bo) {
        return toAjax(tServiceCenterDetailService.insertByBo(bo));
    }

    /**
     * 修改服务中心详情
     */
    @SaCheckPermission("official:serviceCenterDetail:edit")
    @Log(title = "服务中心详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TServiceCenterDetailBo bo) {
        return toAjax(tServiceCenterDetailService.updateByBo(bo));
    }

    /**
     * 删除服务中心详情
     * @param ids 主键串
     */
    @SaCheckPermission("official:serviceCenterDetail:remove")
    @Log(title = "服务中心详情", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tServiceCenterDetailService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 官网-商务配套设施商务配套设施
     *
     * @param areaType  区域类型 0:国内；1：国际
     * @return 服务中心列表
     */
    @SaIgnore
    @GetMapping("/alist")
    public TableDataInfo<TServiceCenterDetailVo>  queryList(String areaType){
        return tServiceCenterDetailService.queryList(areaType);
    }
}
